var productId;//商品id
var guigeId;//规格
var productCount;//商品
var productPrice;//商品价格
var productGuiGe;//商品规格
var imggroup;//图组
var productComment;//评论
$(function () {
    var str="";
    productId="199";
    $.ajax({
        url:"http://localhost:8092/selectProductDetailById?productId="+productId,
        success:function (result) {
            if(result.msgCode=="000000"){
                alert("begin---->");
                var data=result;
                var obj=data.data;
                $.each(obj,function (index,items) {
                    console.log(items);
                    productPrice=items.productPrice;
                    productGuiGe=items.productGuiGe;
                    productComment=items.productComment;
                    //价格
                    for (var i in productPrice) {
                        // $('#pro-price').html(productPrice[i].proPrice);//
                        // $('#coupon').html(productPrice[i].coupon);
                        // $('#yzdianzhu').html(productPrice[i].yzDianzhu);
                        $('#ft17').append("<span class=\"ft10\">￥</span>"+productPrice[i].proPrice);
                    }

                    //规格
                    for(var j in productGuiGe){
                        $('#guige').html(productGuiGe[j].proColor);
                        $('#proSize').html(productGuiGe[j].proSize);
                        $('#proLength').html(productGuiGe[j].proLength);
                        $('#proHeight').html(productGuiGe[j].proHeight);
                        $('#proWidth').html(productGuiGe[j].proWidth);
                        $('#product-img').attr('src',productGuiGe[j].imgurl);
                        imggroup=productGuiGe[j].imgGroup.split(",");
                        guigeId= productGuiGe[j].guigeId;

                        alert(j);
                        // console.log(imggroup.split(","));
                        // $('.pro-imggroup').attr("src",productGuiGe[j].imgGroup);
                    }
                    //图组
                    for (var k in imggroup){
                        console.log("---->"+imggroup[k]);
                        // $('#pro-imggroup').attr('src',imggroup[2]);
                        // $('.swiper-slide').append("<img class='imggroups' src='" +imggroup[k]+ "'>" + "</img>");
                        // $('.w100').attr("src","http://localhost:8092/"+imggroup[1]);
                        $('.swiper-wrapper').append("<div class=\"swiper-slide\">\n" +
                            "<img class=\"w100\" src=\""+"http://localhost:8092/"+imggroup[k]+"\">\n" +
                            "</div>");

                    }

                    //评论
                    for(var n in productComment){
                        $('#pro-comment').html(productComment[n].cContent);

                    }

                })
            }
        }
    })
})

function addCart() {
    var num=$('#count').val();
    var nums=parseInt(num);
    var productIds=parseInt(productId);
    var guigeIds=parseInt(guigeId);
    alert("--id--->"+guigeIds);
    $.ajax({
        url:"/addCart?productId="+productIds+"&guigeId="+guigeIds+"&productCount="+nums,
        success:function (result) {
            alert(result);
        }
    })
}

function JianShuLian(){
    var count=$('#count').val();
    if(count>1){
        count=count-1;
        $('#count').attr('value',count);
    }else{
        count=1;
        $('#count').attr('value',count);
    }
}

function JiaShuLian() {
    var count=$('#count').val();
    var counts=parseInt(count);
    counts=counts+1;
    $('#count').attr('value',counts);
}

